package chapter6;

import javax.vecmath.*;
import java.awt.*;
import java.awt.event.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.geometry.*;

public class Icosahedron extends Shape3D{
   public Icosahedron() {
    GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
    double phi = 0.5*(Math.sqrt(5)+1);
    Point3d[] vertices = {new Point3d(0,phi,1),
    new Point3d(1,0,phi),new Point3d(-1,0,phi),new Point3d(-phi,1,0),
    new Point3d(0,phi,-1),new Point3d(phi,1,0),
    new Point3d(0,-phi,1),new Point3d(-phi,-1,0),new Point3d(-1,0,-phi),
    new Point3d(1,0,-phi),new Point3d(phi,-1,0),
    new Point3d(0,-phi,-1)};
    gi.setCoordinates(vertices);
    int[] indices = {0,1,2, 0,2,3, 0,3,4, 0,4,5, 0,5,1,
    1,10,6, 2,6,7, 3,7,8, 4,8,9, 5,9,10,
    1,6,2, 2,7,3, 3,8,4, 4,9,5, 5,10,1,
    6,11,7, 7,11,8, 8,11,9, 9,11,10, 10,11,6};
    gi.setCoordinateIndices(indices);
    int[] stripCounts = {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3};
    gi.setStripCounts(stripCounts);
    NormalGenerator ng = new NormalGenerator();
    ng.setCreaseAngle(0);
    ng.generateNormals(gi);
    this.setGeometry(gi.getGeometryArray());
  }
}
